package com.a3dweijing.wetouch2.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.a3dweijing.wetouch2.Common.CallBack;
import com.a3dweijing.wetouch2.R;
import com.a3dweijing.wetouch2.adapter.ReportInfoAdapter;
import com.a3dweijing.wetouch2.base.BaseActivity;
import com.a3dweijing.wetouch2.bean.ReportInfoMSg;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by Yxd on 2018/3/22.
 */

public class ReporterinfoActivity extends BaseActivity implements CallBack
{
    @BindView(R.id.back)
    ImageView back;
    
    @BindView(R.id.top_text)
    TextView topText;
    
    @BindView(R.id.top_right)
    TextView topRight;
    
    @BindView(R.id.top_all)
    RelativeLayout topAll;
    
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    
    @BindView(R.id.resaut_status_img)
    ImageView resautStatusImg;
    
    @BindView(R.id.resaut_status)
    LinearLayout resautStatus;
    
    @BindView(R.id.loading_date)
    LinearLayout loadingDate;
    
    private String tel;
    
    private long creat_time;
    
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_health_report_info);
        ButterKnife.bind(this);
        initView();
        initData();
    }
    
    private void initView()
    {
        tel = getIntent().getStringExtra("user_tel");
        creat_time = getIntent().getLongExtra("create_time", 0);
        topText.setText("健康报告");
        recyclerView.setLayoutManager(new LinearLayoutManager(getBaseContext()));
    }
    
    private void initData()
    {loadingDate.setVisibility(View.VISIBLE);
        OkGo.post("http://admin.3dweijing.com/admin.php/api/member/healthReportInfo")
            .tag(ReporterinfoActivity.this)
            .params("user_tel", tel)
            .params("create_time", creat_time)
            .execute(new StringCallback()
            {
                @Override
                public void onSuccess(String s, Call call, Response response)
                {
                    loadingDate.setVisibility(View.GONE);
                    Log.e("--", "onSuccess: " + s);
                    ReportInfoMSg mSg = new Gson().fromJson(s, ReportInfoMSg.class);
                    if (mSg.getFlag())
                    {
                        if (mSg.getList() != null && mSg.getList().size() > 0)
                        {
                            resautStatus.setVisibility(View.GONE);
                            recyclerView.setAdapter(new ReportInfoAdapter(mSg.getList(), ReporterinfoActivity.this));
                        }
                        else
                        {
                            resautStatus.setVisibility(View.VISIBLE);
                            
                        }
                    }
                    else
                    {

                        resautStatus.setVisibility(View.VISIBLE);
                    }
                }
                
                @Override
                public void onError(Call call, Response response, Exception e)
                {
                    super.onError(call, response, e);
                    loadingDate.setVisibility(View.GONE);
                    Log.e("--", "onError: " + e);
                }
            });
        
    }
    
    @OnClick(R.id.back)
    public void onViewClicked()
    {
        finish();
    }
    
    @Override
    public void doNext(int what, Object obj)
    {
        ReportInfoMSg.ListBean bean = (ReportInfoMSg.ListBean)obj;
        Intent intent = new Intent(ReporterinfoActivity.this, ReportWebViewActivity.class);
        intent.putExtra("bean", bean);
        startActivity(intent);
        
    }
}
